package com.example.springboottest.example.io.redirect;

import java.io.FileInputStream;
import java.util.Scanner;

public class RedirectIn {
    public static void main(String[] args) {
        System.out.println(System.getProperty("user.dir"));
        System.out.println(RedirectIn.class.getResource(""));
        try (
                FileInputStream fis = new FileInputStream("src/main/java/com/example/springboottest/example/io/redirect/RedirectIn.java")
//                FileInputStream fis = new FileInputStream("/Users/fangdaye/work/workspace/spring-boot-test/src/main/java/com/example/springboottest/example/io/redirect/RedirectIn.java")
        ) {
            // 将标准输入重定向 fis 输入流
            System.setIn(fis);
            //使用System.in 创建 Scanner 对象，用于获取标准输入
            Scanner sc = new Scanner(System.in);
            // 增加下面 行只把回车作为分隔符
            sc.useDelimiter("\n");
            while (sc.hasNext()) {
                // 输出输入项
                System.out.println(sc.next());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}